using NFreeMarker.Template.Utility;

namespace NFreeMarker.Core
{
    /**
     * An instruction that reduces all sequences of whitespace to a single
     * space or newline. In addition, leading and trailing whitespace is removed.
     * @version $Id: CompressedBlock.java,v 1.1 2003/04/22 21:05:00 revusky Exp $
     * @see freemarker.template.utility.StandardCompress
     */
    public sealed class CompressedBlock : TemplateElement // NOTE: Was internal
    {
        internal CompressedBlock(TemplateElement nestedBlock)
        {
            NestedBlock = nestedBlock;
        }

        internal override void Accept(Environment env)
        {
            if (NestedBlock != null)
            {
                env.Visit(NestedBlock, StandardCompress.Instance, null);
            }
        }

        public override string GetCanonicalForm()
        {
            string nested = NestedBlock != null ? NestedBlock.GetCanonicalForm() : "";
            return "<#compress>" + nested + "</#compress>";
        }

        public override string GetDescription()
        {
            return "compressed block";
        }

        internal override bool IsIgnorable()
        {
            return NestedBlock == null || NestedBlock.IsIgnorable();
        }
    }
}